<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<meta name="x5-orientation" content="portrait" />
		<meta name="x5-fullscreen" content="true" />
		<meta name="screen-orientation" content="portrait" />
		<meta name="full-screen" content="yes" />
		<link rel="stylesheet" type="text/css" href="css/reset.css" />
		<link rel="stylesheet" type="text/css" href="css/layer_mobile.css" />
		<link rel="stylesheet" href="css/personal_application.css" />
		<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
		<script type="text/javascript" src="js/layer_mobile.js"></script>
		<script type="text/javascript" src="js/index.js"></script>
		<title>个人申请</title>
	</head>

	<body>
		<!-- header_头部 -->
		<header class="header">
			<div>
				<a href="personal_center.html"></a>
				<form action="" method="post">
					<label><i></i><input type="text" value="" placeholder="搜索订单号" /></label>
				</form>
			</div>
		</header>
		<!-- section_骨架 -->
		<section class="section">
			<ul id="list-box">
				<script id="list-temp" type="text/html">
					{{each list as rs i}}
					<li>
						<div class="f1_bof" data-id="{{rs.id}}">
							<div class="appli_title">
								<em class="left"><span><img src="images/icon/icon_37.png" alt="" /></span><i>{{ rs.username }}</i></em>
								<p class="right">{{rs.loanStatus|formatLoanStatus}}</p>
							</div>
							<div class="appli_center">
								<div>
									<p>合同号:<i>{{ rs.contractNumber}}</i></p>
									<p>申请日期:<i>{{ rs.addTime|getMyDate}}</i></p>
								</div>
							</div>
						</div>
						{{if rs.loanStatus=="FIRST_TRIAL_PASS"}}
						<a href="javascript:;" data-id="{{rs.id}}" class="confirm_btn">确认金额</a>
						{{else if rs.loanStatus=="WAIT_FIRST_CHECK"}}
						<a href="javascript:;" data-id="{{rs.id}}" class="cancel_btn">撤销</a>
						{{else if rs.loanStatus=="WAIT_SIGN"}}
						<a href="javascript:;" data-id="{{rs.signLink}}" class="hetong_btn">查看合同</a>
						{{/if}}
					</li>
					{{/each}}
				</script>
			</ul>
		</section>
	</body>

</html>
<script src="js/template.js" type="text/javascript" charset="utf-8"></script>
<script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script>
	$(function() {
		//跳转保单详情
		$(document).on('click', '.f1_bof', function() {
			var dataId = $(this).attr("data-id");
			window.location.href = './line_item.html?id=' + dataId;
		})
		if(loca_fetch('userid') == '') {
			$('ul').hide()
		} else {
			$('ul').show()
			//贷款详情
			$.ajax({
				type: "get",
				url: site + "/Loan/queryMyApply",
				dataType: 'json',
				data: {
					userId: loca_fetch('userid'),
					page: 0
				},
				success: function(da) {
					$("#list-box").html(template('list-temp', {
						list: da.data.content
					}));
				}
			});
		}

		layui.use(['layer', 'jquery'], function() {
			layer = parent.layer === undefined ? layui.layer : parent.layer,
				$ = layui.jquery;
			$(document).on("click", ".hetong_btn", function() {
				var load = layer.load(),
					url = $(this).attr("data-id");
				if(!url) {
					layer.msg("合同还未生成，请等待");
					layer.close(load);
					return false;
				}
				var index = layui.layer.open({
					title: "查看合同",
					type: 2,
					area: ["100%", "100%"],
					//content: "loan_contract.html",
					content: url,
					success: function(layero, index) {
						layer.close(load);
						//sessionStorage.removeItem("data-id");
					}
				});
				layui.layer.full(index);
			});
		});

		//确认金额
		$(document).on("click", ".confirm_btn", function() {
			localStorage.setItem("dkid", $(this).attr("data-id"));
			window.location.href = "application_checklist.html";
		});

		//撤销
		$(document).on("click", ".cancel_btn", function() {
			var loanId = $(this).attr('data-id')
			layer.open({
				type: 1,
				btn: ['确定', '取消'],
				content: '<textarea placeholder="请输入撤销意见..." style="width: 13rem;height: 5rem;resize:none;outline:none;border:0;padding: 0.4rem;"></textarea>',
				yes: function(index) {
					if($('textarea').val() == "") {
						alerts("请输入撤销意见")
					} else {
						$.ajax({
							type: "get",
							url: site + "/Loan/revokeLoan",
							data: {
								loanId: loanId,
								remark: $('textarea').val()
							},
							success: function(data) {
								location.reload();
								layer.close(index);
							}
						});
					}
				}
			});
		});
	})


</script>